from datetime import date
from PySide6.QtCore import QFile, QIODevice, QDate
from PySide6.QtUiTools import QUiLoader


class TabName(str):
    CHILD_WINDOW1 = "子窗口1"
    CHILD_WINDOW2 = "子窗口2"


def loadUiFile(file_path: str):
    """加载ui文件并获得对应的QWidget"""
    # 查找ui文件
    ui_file = QFile(file_path)
    if not ui_file.open(QIODevice.OpenModeFlag.ReadOnly):
        print(f"无法打开UI文件: {ui_file.errorString()}")
        return

    # 加载UI文件
    loader = QUiLoader()
    ui = loader.load(ui_file)
    ui_file.close()

    if not ui:
        print(f"loader error: {loader.errorString()}")
        return

    return ui


def get_QDate_from_date(d: date) -> QDate:
    """从date转换到QDate"""
    return QDate(d.year, d.month, d.day)


def get_date_from_QDate(qd: QDate) -> date:
    """从QDate转换到date"""
    return date(year=qd.year(), month=qd.month(), day=qd.day())
